package com.toune.movie.base.myview;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Display;
import android.view.KeyboardShortcutGroup;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/11.
 */

public class ShareDialog extends Dialog implements View.OnClickListener{
    public ShareDialog(@NonNull Context context) {
        super(context);
    }
    private Context context;
    private int mLayoutResId;
    private int[] mIds = new int[0];
    private int mAnimationResId = 0;
    private OnCustomDialogItemClickListener listener;
    private boolean mIsDismiss = true;
    private boolean mIsDismissTouchOut = true;
    private int mPosition = 0;
    private List<View> mViews = new ArrayList();

    public void setOnDialogItemClickListener(OnCustomDialogItemClickListener listener) {
        this.listener = listener;
    }

    public ShareDialog(Context context, int layoutResID) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
    }

    public ShareDialog(Context context, int layoutResID, int[] listenedItems) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = listenedItems;
    }

    public ShareDialog(Context context, int layoutResID, int[] listenedItems, int animationResId) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = listenedItems;
        this.mAnimationResId = animationResId;
    }

    public ShareDialog(Context context, int layoutResID, int[] listenedItems, boolean isDismiss) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = listenedItems;
        this.mIsDismiss = isDismiss;
    }

    public ShareDialog(Context context, int layoutResID, int[] listenedItems, boolean isDismiss, boolean isDismissTouchOut) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = listenedItems;
        this.mIsDismiss = isDismiss;
        this.mIsDismissTouchOut = isDismissTouchOut;
    }

    public ShareDialog(Context context, int layoutResID, int[] listenedItems, boolean isDismiss, int position) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = listenedItems;
        this.mPosition = position;
    }

    public ShareDialog(Context context, int layoutResID, int[] ids, int animationResId, boolean isDismiss, boolean isDismissTouchOut, int position) {
        super(context, com.siberiadante.customdialoglib.R.style.Custom_Dialog_Style);
        this.context = context;
        this.mLayoutResId = layoutResID;
        this.mIds = ids;
        this.mAnimationResId = animationResId;
        this.mIsDismiss = isDismiss;
        this.mIsDismissTouchOut = isDismissTouchOut;
        this.mPosition = position;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        if(0 == this.mPosition) {
            window.setGravity(17);
        } else {
            window.setGravity(this.mPosition);
        }

        if(this.mAnimationResId == 0) {
            window.setWindowAnimations(com.siberiadante.customdialoglib.R.style.bottom_animation);
        } else {
            window.setWindowAnimations(this.mAnimationResId);
        }

        this.setContentView(this.mLayoutResId);
        WindowManager windowManager = ((Activity)this.context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.width = display.getWidth();
        this.getWindow().setAttributes(lp);
        this.setCanceledOnTouchOutside(this.mIsDismissTouchOut);
        int[] var6 = this.mIds;
        int var7 = var6.length;

        for(int var8 = 0; var8 < var7; ++var8) {
            int id = var6[var8];
            View view = this.findViewById(id);
            view.setOnClickListener(this);
            this.mViews.add(view);
        }

    }

    public List<View> getViews() {
        return this.mViews;
    }

    public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) {
    }

    public void onClick(View view) {
        if(this.mIsDismiss) {
            this.dismiss();
        }

        this.listener.OnCustomDialogItemClick(this, view);
    }

    public interface OnCustomDialogItemClickListener {
        void OnCustomDialogItemClick(ShareDialog var1, View var2);
    }
}
